/*
 * acooly.cn Inc.
 * Copyright (c) 2017 All Rights Reserved.
 * create by ouwen
 * date:2017-09-20
 */
package com.yiji.fintech.musfinance.service.impl;

import com.acooly.core.common.dao.support.PageInfo;
import com.acooly.core.common.service.EntityServiceImpl;
import com.google.common.collect.Sets;
import com.yiji.fintech.musfinance.base.enums.CardTypeEnum;
import com.yiji.fintech.musfinance.base.enums.PersonalCorporateTypeEnum;
import com.yiji.fintech.musfinance.common.enums.StatusEnum;
import com.yiji.fintech.musfinance.common.exception.DBException;
import com.yiji.fintech.musfinance.dao.RouteRuleDao;
import com.yiji.fintech.musfinance.entity.RouteRule;
import com.yiji.fintech.musfinance.service.RouteRuleService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * center_route_rule Service实现
 *
 * Date: 2017-09-20 22:12:49
 *
 * @author ouwen
 *
 */
@Service("routeRuleService")
public class RouteRuleServiceImpl extends EntityServiceImpl<RouteRule, RouteRuleDao> implements RouteRuleService {

    @Override
    public List<RouteRule> query(RouteRule routeRule, Map<String, Boolean> sortMap, int pageNum, int pageSize) {
        Map<String,Object> map = new HashMap<>();
        map.put("EQ_status", StatusEnum.ON);
        map.put("EQ_partnerId",routeRule.getPartnerId());
        map.put("EQ_transactionType",routeRule.getTransactionType());
        map.put("EQ_subTransactionType",routeRule.getSubTransactionType());
        map.put("EQ_instBankId",routeRule.getInstBankId());
        if(routeRule.getPersonalCorporateType() != null){
            if(routeRule.getPersonalCorporateType() == PersonalCorporateTypeEnum.ALL){
                map.put("IN_personalCorporateType",PersonalCorporateTypeEnum.getAllEnum());
            }else {
                map.put("IN_personalCorporateType", Sets.newHashSet(routeRule.getPersonalCorporateType(),PersonalCorporateTypeEnum.ALL));
            }
        }
        if(routeRule.getCardType()!=null){
            if(routeRule.getCardType() == CardTypeEnum.ALL){
                map.put("IN_cardType",CardTypeEnum.getAll());
            }else {
                map.put("IN_cardType", Sets.newHashSet(routeRule.getCardType(),CardTypeEnum.ALL));
            }
        }
        PageInfo<RouteRule> pageInfo = new PageInfo<>();
        pageInfo.setCurrentPage(pageNum);
        pageInfo.setCountOfCurrentPage(pageSize);
        try {
            pageInfo = getEntityDao().query(pageInfo, map, sortMap);
        } catch (Exception e) {
            throw new DBException(e.getMessage());
        }
        return pageInfo.getPageResults();
    }
}
